package com.ciaj.base.comm.utils;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import java.util.*;
import java.util.stream.Stream;

/**
 * @Description 集合工具类
 * @Author Ciaj.
 * @Date 2019/6/21 10:25
 * @Version 1.0
 */
public class CollectionUtil {
	public static boolean isEmpty(Collection coll) {
		return (coll == null || coll.size() == 0) ? true : false;
	}

	public static boolean isNotEmpty(Collection coll) {
		return (coll != null && coll.size() > 0) ? true : false;
	}

	public static boolean isEmpty(Object[] arrs) {
		return (arrs == null || arrs.length == 0) ? true : false;
	}

	public static boolean isNotEmpty(Object[] arrs) {
		return (arrs != null && arrs.length > 0) ? true : false;
	}

	public static <T> Stream<T> of(List<T> source) {
		return Optional.ofNullable(source).orElse(Lists.newArrayListWithCapacity(0)).stream().filter(x -> x != null);
	}

	public static <T> Stream<T> of(Set<T> source) {
		return Optional.ofNullable(source).orElse(Sets.newHashSetWithExpectedSize(0)).stream().filter(x -> x != null);
	}

	public static <T> Stream<T> of(T... source) {
		return Arrays.stream(source).filter(x -> x != null);
	}
}
